package com.socialmediaanalytics.client.facebook;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.socialmediaanalytics.client.GWTEntryPoint;
import com.socialmediaanalytics.client.facebook.sdk.FBCore;
import com.socialmediaanalytics.client.facebook.sdk.JSOModel;
import com.socialmediaanalytics.client.model.User;



/** 
 * 
 * 
 * @Architecture 
 */

public class FacebookAboutMe {

	public FacebookAboutMe(final FBCore fbCore) {

		fbCore.api("/me", new AsyncCallback<JavaScriptObject>() {

			@Override
			public void onFailure(Throwable caught) {

			}

			@Override
			public void onSuccess(JavaScriptObject result) {

				JSOModel jso = result.cast();

				GWT.log("logged " + result);

				String id = jso.get("id");

				String name = jso.get("name");

				User me = new User(id, name);

				GWTEntryPoint.facebookUser = me;

				GWTEntryPoint.facebookFriends.put(me.getFacebookID(), me);

				new FacebookFriendLikes(fbCore, me.getFacebookID(), true);

				new FacebookFriendMovies(fbCore, me.getFacebookID(), true);

				new FacebookFriendBooks(fbCore, me.getFacebookID(), true);

			}
		});

	}
}
